﻿using EMS.system.Entityies.MasterData.CustomerManagementModel;
using EMS.system.IEntityAppService.MasterData.CustomerManagementIService.CustomerManagementDTO;
using EMS.system.IEntityAppService.MasterData.SalesOutService;
using EMS.system.IEntityAppService.MasterData.SalesOutService.SalesOutDTOs;
using EMS.system.IEntityAppService.MasterData.SupplierManagementIService.SupplierManagementDto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.MasterData.SalesOuts
{
    public class SalesOutController : Controller
    {
        /// <summary>
        /// 销售出库服务类
        /// </summary>
        private readonly ISalesOutAppService _salesOutAppService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="saleOutAppService"></param>
        public SalesOutController(ISalesOutAppService saleOutAppService)
        {
            _salesOutAppService = saleOutAppService;
        }
        /// <summary>
        /// 销售出库显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SalesOutList()
        {
            return View();
        }
        /// <summary>
        /// 销售出库添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult CreateSalesOut()
        {
            return View();
        }
        /// <summary>
        /// 获取销售出库显示 分页 查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="outCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSalesOutList(int page, int limit, string? outCode)
        {
            var salesOut =await _salesOutAppService.GetSalesOutList(page, limit, outCode);
            return Json(new {code=0,count=salesOut.RowCount,data=salesOut.Queryable});
        }
        /// <summary>
        /// 获取客户管理列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<CustomerManagementInsertDTO>> GetCustomerManagement()
        {
            return await _salesOutAppService.GetCustomerManagement();
        }
        /// <summary>
        /// 添加销售出库
        /// </summary>
        /// <param name="salesOutDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateSalesOut(SalesOutDTO salesOutDTO)
        {
            return await _salesOutAppService.CreateSalesOut(salesOutDTO);

        }
        /// <summary>
        /// 删除销售出库
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteSalesOut(string ids)
        {
            return  await _salesOutAppService.DeleteSalesOut(ids);
        }
        /// <summary>
        /// 获取销售出库单主键id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SalesOutDTO> GetSalesOutById(int id)
        {
            return await _salesOutAppService.GetSalesOutById(id);
        }
        /// <summary>
        /// 更新销售出库
        /// </summary>
        /// <param name="salesOutDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdaetSalesOut(SalesOutDTO salesOutDTO)
        {
            return await _salesOutAppService.UpdaetSalesOut(salesOutDTO);
        }
    }
}
